<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>从session中获取值</h2>
<span th:text="${#session.getAttribute('data')}"></span><br>
<span th:text="${#httpSession.getAttribute('data')}"></span><br>
<span th:text="${session.data}"></span><br>

<h2>从request中获取值</h2>
<script type="text/javascript" th:inline="javascript">
    //http://localhost:8080/expression
    //获取协议名称
    var scheme=[[${#request.getScheme()}]];

    //获取服务器名称
    var serverName=[[${#request.getServerName()}]];

    //获取服务器端口号
    var serverPort=[[${#request.getServerPort()}]];

    //获取上下文根
    var contextPath=[[${#request.getContextPath()}]];

    //获取请求路径
    var requestURL=[[${#httpServletRequest.requestURL}]];

    //获取请求参数
    var queryString=[[${#httpServletRequest.queryString}]];

    //拼接成字符串
    var urlPath=scheme+"://"+serverName+":"+serverPort+contextPath;

    alert(urlPath);
    alert(requestURL);
    alert(queryString);
</script>
</body>
</html>